<?
if ($this->id)
    $title = 'Редактирование юзера';
else
    $title = 'Добавление юзера';
?>
<h1><?=$title;?></h1>
<form action="<?=MozgRoute::Get('http')->Create(array('module' => 'admin', 'ctrl' => 'users', 'action' => 'save_user'));?>"
	method="post" enctype="multipart/form-data">
<table align="center" class="formTable">
	<tr>
		<td class="field-title"><label>Логин</label></td>
		<td class="field-place"><input name="username" type=text
			value="<?=htmlspecialchars($this->user->GetUserName());?>"></td>
	</tr>
	<tr>
		<td class="field-title"><label>Имя</label></td>
		<td class="field-place"><input name="fullname" type=text
			value="<?=htmlspecialchars($this->user->GetFullName());?>"></td>
	</tr>
	<tr>
		<td class="field-title"><label>Email</label></td>
		<td class="field-place"><input name="email" type=text
			value="<?=htmlspecialchars($this->user->GetEmail());?>"></td>
	</tr>
	<tr>
		<td class="field-title"><label>Аватар</label></td>
		<td class="field-place">
		<?php 
			if ($this->user->GetAvatar())
			{
		?>
		<img src="<?=_ROOT_URL.$this->thumbPath.$this->user->GetAvatar();?>">
		<?php 
			}
		?><br>		
		<input type="file" name="avatar"></td>
	</tr>		
	<tr>
		<td class="field-title"><label>Пароль</label></td>
		<td class="field-place"><input name="password1" type="password"></td>
	</tr>
	<tr>
		<td class="field-title"><label>Повторите пароль</label></td>
		<td class="field-place"><input name="password2" type="password"></td>
	</tr>
	<tr>
		<td class="field-title"><label>Заблокирован</label></td>
		<td class="field-place"><input name="blocked" type="checkbox" value="1"
			<?=($this->user->GetBlocked() ? ' checked' : '');?>></td>
	</tr>
	<tr>
		<td class="field-title"><label>Группы</label></td>
		<td class="field-place">
		<table cellspacing="0" cellpadding="1" id="group_section">
<?
while (list (, $v) = each($this->myGroups)) 
{
    ?>
					<tr>
				<td width="1"><input title="Основная группа" type="radio"
					name="group_id" value="<?=$v->GetId();?>"
					<?=($this->user->GetUserGroup() == $v->GetId() ? ' checked' : '');?>></td>
				<td id="group_title_<?=$v->GetId();?>" class="group_title"><?=$v->GetTitle();?></td>
				<td width="1"><input title="Дополнительная группа" type="checkbox"
					name="grant_groups[]" value="<?=$v->GetId();?>"
					<?=(in_array($v->GetId(), $this->user->GetGrantedGroups()) ? ' checked' : '');?>></td>
			</tr>
<?
}
?>
		</table>
		</td>
	</tr>
</table>
<table>
	<tr>
		<td class="r"><input type="submit" value="Сохранить" class="bt" /></td>
		<td class="l"><input type="button" value="Назад" class="bt"
			onClick="window.location.href='<?=MozgRoute::Get('http')->Create(array('module' => 'admin', 'ctrl' => 'users'));?>';" /></td>
	</tr>
</table>
<input type="hidden" name="id" value="<?=$this->id;?>"></form>
<script type="text/javascript">
var gsection;

$(document).ready(
	function()
	{
		gsection = $('#group_section');

		activateGroup(gsection.find('input:radio:checked'));
		gsection.find('input:radio').click(function () {activateGroup(this);});
	}
);

function activateGroup(obj)
{
	var id = $(obj).val();

	gsection.find("input:checkbox:hidden").show();
	gsection.find("input:checkbox[value='" +id+ "']").hide();

	gsection.find('.group_title').css('font-weight', 'normal');
	gsection.find('#group_title_' +id).css('font-weight', 'bold');
}
</script>